package com.qfmy.app.mapper.novel;

import com.qfmy.model.entity.novel.Book;
import com.qfmy.model.entity.query.CategoryQuery;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.app.mapper.novel
 * @date 2025/4/14
 * @description 小说的mapper
 */
@Mapper
@SuppressWarnings("all")
public interface BookMapper {

    /**
     * 查询top3的前三本
     * @return
     */
    List<Book> selectTopThree(Integer count);

    /**
     * 分页查询
     * @param start
     * @param size
     * @return
     */
    List<Book> selectPage(int start, int size);

    /**
     * 根据类别推荐
     * @param categories
     * @param readIds
     * @param count
     * @return
     */
    List<Book> selectRecommendationsByCategories(@Param("categories") List<String> categories, @Param("readIds") List<Integer> readIds);

    /**
     * 根据类别查询
     * @param start
     * @param size
     * @param name
     * @return
     */
    List<Book> selectByCategory(CategoryQuery categoryQuery);

    /**
     * 根据阅读量查询
     * @param categoryQuery
     * @return
     */
    List<Book> selectByReadCount(CategoryQuery categoryQuery);

    /**
     * 根据评分查询
     * @param categoryQuery
     * @return
     */
    List<Book> selectByScore(CategoryQuery categoryQuery);

    /**
     * 根据更新时间查询
     * @param categoryQuery
     * @return
     */
    List<Book> selectByUpdateTime(CategoryQuery categoryQuery);

    /**
     * 根据id查询
     *
     * @param bookId
     * @param userId
     * @return
     */
    Book selectById(Long bookId, Integer userId);

    /**
     * 根据id更新评分
     * @param bookId
     * @param score
     */
    @Update("update book set rating_count = rating_count + 1, total_score = (total_score * rating_count + #{score}) / (rating_count + 1) where book_id = #{bookId}")
    void updateBookByBookId(Long bookId,Double score);

    /**
     * 查询推荐
     * @param start
     * @param size
     * @return
     */
    List<Book> selectRecommend(int start, int size);

    /**
     * 查询完结
     * @param start
     * @param size
     * @return
     */
    List<Book> selectByComplete(int start, int size);

    /**
     * 查询最新
     * @param start
     * @param size
     * @return
     */
    List<Book> selectByNew(int start, int size);

    /**
     * 查询所有
     * @return
     */
    List<Book> getAllBooks();

    /**
     * 更新搜索次数
     * @param id
     */
    @Update("update book set search_count = search_count + 1 where book_id = #{id}")
    void updateSearchCount(Long id);

    /**
     * 更新阅读次数
     * @param id
     */
    @Update("update book set read_book= read_book + 1 where book_id = #{id}")
    void updateReadCount(Long id);

    /**
     * 查询热搜
     * @param start
     * @param size
     * @return
     */
    List<Book> selectHotSearch(int start, int size);
}
